package com.zzsy.carosshopprojects.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;

import com.king.base.adapter.ViewHolderRecyclerAdapter;
import com.king.base.adapter.holder.ViewHolder;
import com.king.base.util.ToastUtils;
import com.yatoooon.screenadaptation.ScreenAdapterTools;
import com.zzsy.carosshopprojects.R;
import com.zzsy.carosshopprojects.bean.ChangeShiftsBean;
import com.zzsy.carosshopprojects.util.DataUtil;
import com.zzsy.carosshopprojects.util.FormatTimeUtil;
import com.zzsy.carosshopprojects.util.ViewBgUtil;
import com.zzsy.carosshopprojects.util.sunmiprint.PrintHelper;

import java.util.List;

import androidx.appcompat.app.AlertDialog;

public class ChangeShiftsAdapter extends ViewHolderRecyclerAdapter<ChangeShiftsBean.ListBean> {


    public ChangeShiftsAdapter(Context context, List<ChangeShiftsBean.ListBean> listData, int layoutId) {
        super(context, listData, layoutId);
    }

    @Override
    public View buildConvertView(LayoutInflater layoutInflater, ViewGroup parent, int viewType) {
        View view = layoutInflater.inflate(R.layout.adapter_changeshifts, null);
        ScreenAdapterTools.getInstance().loadView(view);
        return view;
    }

    @Override
    public void bindViewDatas(ViewHolder helper, ChangeShiftsBean.ListBean bean, int positions) {
        helper.setText(R.id.tv_tremin_name, "设备名称：" + bean.getTerminalName());
        helper.setText(R.id.tv_start_time, FormatTimeUtil.formatTimeStamp2DateStr(String.valueOf(Long.parseLong(bean.getStartTime()) / 1000), "yyyy-MM-dd HH:mm:ss"));
        helper.setText(R.id.tv_end_time, FormatTimeUtil.formatTimeStamp2DateStr(String.valueOf(Long.parseLong(bean.getEndTime()) / 1000), "yyyy-MM-dd HH:mm:ss"));
        if (DataUtil.getInstance().getCustomerType().equals("1"))//加油员
            helper.setText(R.id.tv_order_num, bean.getOrderCount());
        else if (DataUtil.getInstance().getCustomerType().equals("2"))//吧台
            helper.setText(R.id.tv_order_num, bean.getTotalOrder());
        RelativeLayout cl = helper.getView(R.id.cl);
        cl.setBackground(ViewBgUtil.setBg(15, Color.parseColor("#ffffff")));
        helper.getConvertView().setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                printDialog(bean);
            }
        });
    }

    public void printDialog(ChangeShiftsBean.ListBean bean) {
        final AlertDialog.Builder dialog = new AlertDialog.Builder(getContext());
        dialog.setTitle(getContext().getResources().getString(R.string.tips))
                .setMessage(getContext().getResources().getString(R.string.surePrintTicket))
                .setPositiveButton(getContext().getResources().getString(R.string.sure), (dialog1, which) -> {
                    if (DataUtil.getInstance().getCustomerType().equals("1"))
                        PrintHelper.getInstance().printChangeShiftsStaff(bean);
                    else if (DataUtil.getInstance().getCustomerType().equals("2"))
                        PrintHelper.getInstance().printChangeShiftsBar(bean);
                    else
                        ToastUtils.showToast(getContext().getApplicationContext(), getContext().getApplicationContext().getResources().getString(R.string.errPrint));

                })
                .setNegativeButton(getContext().getResources().getString(R.string.cancel), (dialog12, which) -> {
                });
        AlertDialog dialog_dialog = dialog.create();
        dialog_dialog.show();
    }
}
